package com.itheima.dao;

import com.itheima.domain.OrderSetting;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 预约设置数据的持久层
 */
public interface OrderSettingDao {

    /**
     * 批量添加预约数据
     *
     * @param orderSetting
     */
    @Insert("insert into t_ordersetting(orderDate,number,reservations) values(#{orderDate},#{number},#{reservations})")
    void insertBatchOrderSetting(OrderSetting orderSetting);

    /**
     * 根据预约日期修改可预约人数
     *
     * @param orderSetting
     */
    @Update("update t_ordersetting set number=#{number} where orderDate=#{orderDate}")
    void updateNumberByDate(OrderSetting orderSetting);

    /**
     * 根据预约日期查询是否有预约数据
     *
     * @param orderDate
     * @return
     */
    @Select("select count(id) from t_ordersetting where orderDate=#{orderDate}")
    Integer selectCountByDate(Date orderDate);

    /**
     * 查询预约日期范围的预约数据
     *
     * @param beginDate
     * @param endDate
     * @return
     */
    @Select("select dayofmonth(orderDate) date,number,reservations from t_ordersetting where orderDate between #{beginDate} and #{endDate}")
    List<Map<String, String>> findOrderSettingByDate(@Param("beginDate") String beginDate, @Param("endDate") String endDate);

    /**
     * 根据预约日期查询预约数据
     * @param orderDate
     * @return
     */
    @Select("select * from t_ordersetting where orderDate=#{orderDate}")
    OrderSetting selectByDate(String orderDate);

    /**
     * 根据日期修改已预约人数
     * @param orderDate
     */
    @Update("update t_ordersetting set reservations=reservations+1 where orderDate=#{orderDate}")
    void updateReservationsByDate(String orderDate);
}
